package com.sz.biz.common.platform.service.impl;

import com.sz.biz.common.platform.entity.PlatformCompany;
import com.sz.biz.common.customer.dto.CusCustomerTradeDto;
import com.sz.biz.common.platform.service.PlatformCompanyService;
import com.sz.common.base.dao.ParamData;
import com.sz.common.base.service.AbstractService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Function: PlatformCompanyServiceImpl <br>
 * Date: 2017年08月02日 15:43 <br>
 * Author: wentao.chang
 */
@Service
public class PlatformCompanyServiceImpl extends AbstractService implements PlatformCompanyService {

    @Override
    public List<PlatformCompany> findAll() {
        return dao.findForList("PlatformCompanyMapper.findAll", null, PlatformCompany.class);
    }

    /**
     * 按平台公司的id查询公司
     *
     * @param companyId
     * @return comapny
     */
    @Override
    public PlatformCompany getPlatformCompanyById(Integer companyId) {
        List<PlatformCompany> list = findAll();
        final PlatformCompany[] find = {null};
        list.forEach(company -> {
            if (company.getId().equals(companyId)) {
                find[0] = company;
            }
        });
        return find[0];
    }

    /**
     * 根据code查询
     * @param code
     * @return
     */
    @Override
    public PlatformCompany findByCode(String code){
        return (PlatformCompany) dao.findForObject(getSqlName("PlatformCompanyMapper.findByCode"), code);
    }

    /**
     * 根据code查询
     * @param purchaseCustomerCodes
     * @return
     */
    @Override
    public List<CusCustomerTradeDto> findByCodes(List<String> purchaseCustomerCodes){
        ParamData paramData = new ParamData();
        paramData.put("customerCodes", purchaseCustomerCodes);
        return dao.findForList(getSqlName("PlatformCompanyMapper.findByCodes"), paramData, CusCustomerTradeDto.class);
    }
}
